<%@page import="qldc.pm.tiensu.model.TienSu"%>
<%@page import="com.liferay.portal.kernel.util.Constants"%>
<%@page import="qldc.pm.qtht.dmdc.service.TonGiaoLocalServiceUtil"%>
<%@page import="qldc.pm.qtht.dmdc.model.TonGiao"%>
<%@page import="qldc.pm.qtht.dmdc.service.DanTocLocalServiceUtil"%>
<%@page import="qldc.pm.qtht.dmdc.model.DanToc"%>
<%@page import="qldc.pm.qtht.dmdc.enumclass.EnumGioiTinh"%>
<%@page import="com.liferay.portal.kernel.util.Validator"%>
<%@page import="qldc.pm.csdl.cd90.service.CongDanDTOLocalServiceUtil"%>
<%@page import="qldc.pm.csdl.cd90.model.dto.CongDanDTO"%>
<%@page import="qldc.pm.qtht.dmdc.utils.DiaChiUtils"%>
<%@page import="qldc.pm.tiensu.service.DoiTuongTienSuLocalServiceUtil"%>
<%@page import="qldc.pm.tiensu.model.DoiTuongTienSu"%>
<%@page import="qldc.pm.tiensu.util.DateUtils"%>
<%@page import="qldc.pm.tiensu.service.TienSuLocalServiceUtil"%>
<%@include file="../../init.jsp"%>

<%
String redirect = ParamUtil.getString(request, "redirect");
String yeuCauTrichLucId = ParamUtil.getString(request, "yeuCauTrichLucId");
String soDinhDanhCaNhan = ParamUtil.getString(request, "soDinhDanhCaNhan");

long doiTuongTienSuId = ParamUtil.getLong(request, "doiTuongTienSuId");
TienSu tienSuLatest = TienSuLocalServiceUtil.findByDoiTuongTienSuId_Latest(doiTuongTienSuId);
PortletURL inReportURL = renderResponse.createActionURL();
inReportURL.setParameter(TienSuConstants.ACTION_HANDLER_PARAM, TienSuConstants.REPORT_ACTION);
inReportURL.setParameter(Constants.ACTION, "inReportTrichLuc");
inReportURL.setParameter("redirect", redirect);
inReportURL.setParameter("tienSuId", String.valueOf(tienSuLatest.getTienSuId()));
inReportURL.setParameter("yeuCauTrichLucId", yeuCauTrichLucId);
inReportURL.setParameter("soDinhDanhCaNhan", soDinhDanhCaNhan);

String hoVaTen = "";
String gioiTinhKey = "";
String soCMND = "";
String soSoHoKhau = "";
String noiThuongTru = "";
String ngaySinh = "";
String danToc = "";
String tonGiao = "";
String quocTich = "";
String hoVaTenCha = "";
String hoVaTenMe = "";

CongDanDTO congDanDTO = CongDanDTOLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);

if(Validator.isNotNull(congDanDTO)) {
	hoVaTen = congDanDTO.getHoVaTen();
	
	gioiTinhKey = EnumGioiTinh.getKey(congDanDTO.getGioiTinh());
	
	soCMND = congDanDTO.getSoCMND();
	soSoHoKhau = congDanDTO.getSoSoHoKhau();
	
	long noiThuongTruQuanHuyenId = congDanDTO.getNoiThuongTruQuanHuyenId();
	long noiThuongTruPhuongXaId = congDanDTO.getNoiThuongTruPhuongXaId();
	String noiThuongTruDiaChi = congDanDTO.getNoiThuongTruDiaChi();
	
	noiThuongTru = DiaChiUtils.createBlockDiaChi(noiThuongTruQuanHuyenId, noiThuongTruPhuongXaId, noiThuongTruDiaChi);
	
	ngaySinh = congDanDTO.getNgaySinh();
	
	long danTocId = congDanDTO.getDanTocId();
	if(danTocId > 0) {
		DanToc dmdcDanToc = DanTocLocalServiceUtil.findById(danTocId);
		
		if(Validator.isNotNull(dmdcDanToc)) {
			danToc = dmdcDanToc.getTenDanToc();
		}
	}
	
	long tonGiaoId = congDanDTO.getTonGiaoId();
	if(tonGiaoId > 0) {
		TonGiao dmdcTonGiao = TonGiaoLocalServiceUtil.findById(tonGiaoId);
		
		if(Validator.isNotNull(dmdcTonGiao)) {
			tonGiao = dmdcTonGiao.getTenTonGiao();
		}
	}
	
	quocTich = congDanDTO.getQuocTich();
	hoVaTenCha = congDanDTO.getHoVaTenCha();
	hoVaTenMe = congDanDTO.getHoVaTenMe();
}
%>

<table class="gridnormal">
	<tr>
		<td class="txtlabel aui-w20"><liferay-ui:message key="ho-va-ten" /></td>
		<td class="aui-w30"><font style="font-weight: bold;"><%=hoVaTen %></font></td>
		<td class="txtlabel aui-w20"><liferay-ui:message key="gioi-tinh" /></td>
		<td class="aui-w30"><font style="font-weight: bold;"><liferay-ui:message key="<%=gioiTinhKey %>"></liferay-ui:message></font></td>
	</tr>
	
	<tr>
		<td><liferay-ui:message key="so-dinh-danh-ca-nhan" /></td>
		<td><font style="font-weight: bold;"><%=soDinhDanhCaNhan %></font></td>
		<td><liferay-ui:message key="so-cmnd" /></td>
		<td><font style="font-weight: bold;"><%=soCMND %></font></td>
	</tr>

	<tr>
		<td><liferay-ui:message key="so-so-ho-khau" /></td>
		<td><font style="font-weight: bold;"><%=soSoHoKhau %></font></td>
		<td><liferay-ui:message key="ngay-sinh" /></td>
		<td><font style="font-weight: bold;"><%=ngaySinh %></font></td>
	</tr>
	
	<tr>
		<td><liferay-ui:message key="noi-thuong-tru" /></td>
		<td><font style="font-weight: bold;"><%=noiThuongTru %></font></td>
		<td><liferay-ui:message key="dan-toc" /></td>
		<td><font style="font-weight: bold;"><%=danToc %></font></td>
	</tr>
	
	<tr>
		<td><liferay-ui:message key="ton-giao" /></td>
		<td><font style="font-weight: bold;"><%=tonGiao %></font></td>
		<td><liferay-ui:message key="quoc-tich" /></td>
		<td><font style="font-weight: bold;"><%=quocTich %></font></td>
	</tr>
	
	<tr>
		<td><liferay-ui:message key="ho-va-ten-cha" /></td>
		<td><font style="font-weight: bold;"><%=hoVaTenCha %></font></td>
		<td><liferay-ui:message key="ho-va-ten-me" /></td>
		<td><font style="font-weight: bold;"><%=hoVaTenMe %></font></td>
	</tr>
	
	
	<tr>
		<td></td>
		<td colspan="3">
			<div align="left">
				<input type="button" class="btn btn-primary" value="<liferay-ui:message key="trich-luc" />" onclick="javascript:inDuLieu('<%=inReportURL.toString() %>');"/>
				<input type="button" class="btn" onclick="javascript:submitForm(document.hrefFm,'<%=redirect %>');" value="<liferay-ui:message key="tro-ve" />" />
			</div>
		</td>
	</tr>
</table>

<liferay-ui:search-container emptyResultsMessage="khong-tim-thay-tien-su">
	<liferay-ui:search-container-results>
		<%
			results = TienSuLocalServiceUtil.findByDoiTuongTienSuId(doiTuongTienSuId);

			total = TienSuLocalServiceUtil.countByDoiTuongTienSuId(doiTuongTienSuId);

			pageContext.setAttribute("results", results);
			pageContext.setAttribute("total", total);
		%>
	</liferay-ui:search-container-results>
	
	<%
		int start = searchContainer.getDelta() * (searchContainer.getCur() - 1);
	%>
	
	<liferay-ui:search-container-row className="qldc.pm.tiensu.model.TienSu" keyProperty="tienSuId" modelVar="tienSu">
		<liferay-ui:search-container-column-text cssClass="aui-w3 txt-center" name="stt" value="<%=String.valueOf(++start)%>" />
		<liferay-ui:search-container-column-text name="toi-danh" value="<%=tienSu.getToiDanh()%>" />
		<liferay-ui:search-container-column-text name="noi-dung-xu-phat" value="<%=tienSu.getHinhPhatChinh()%>" />
		<liferay-ui:search-container-column-text name="ngay-pham-toi" value="<%=DateUtils.printDate(tienSu.getNgayPhamToi())%>" />
		<liferay-ui:search-container-column-jsp cssClass="aui-Action" path="/html/tiensu/nguoi_co_tien_su/tien_su_actions.jsp" align="right" />
	</liferay-ui:search-container-row>

	<liferay-ui:search-iterator/>
</liferay-ui:search-container>
<script>
function inDuLieu(url) {
	var form = $("<form>").attr({action: url, method:"POST",target:"_blank"});				
	form.appendTo(document.body).submit();
	
}
</script>